import asyncio, logging
log = logging.getLogger(__name__)

class LifecycleManager:
    def __init__(self, coros) -> None:
        print(f"[DEBUG] 进入函数: LifecycleManager.__init__")
        self.tasks = [asyncio.create_task(c) for c in coros]

    async def __aenter__(self):
        print(f"[DEBUG] 进入函数: LifecycleManager.__aenter__")
        return self

    async def __aexit__(self, *_):
        print(f"[DEBUG] 进入函数: LifecycleManager.__aexit__")
        for t in self.tasks:
            t.cancel() 
        await asyncio.gather(*self.tasks, return_exceptions=True)